import React, {useEffect, useState} from 'react'

import {View,Text} from '@tarojs/components'

import store from "../../../../store";

export default function OrderNav(){
  const [currOrderNav,useCurrOrderNav] = useState(store.getState().currOrderNav)

  useEffect(() => {
    store.subscribe(stateChane)
  },[])
    function stateChane() {
      useCurrOrderNav(store.getState().currOrderNav)
    }
    function changeOrderNav(index){
      const action = {
        type: 'change_order_nav',
        index
      }
      store.dispatch(action)
    }
  return (
    //is_curr_order_nav
    <View className='order_nav'>
      <Text className={`order_nav_item ${currOrderNav === 0? 'is_curr_order_nav':''}`} onClick={() => {changeOrderNav(0)}}>全部</Text>
      <Text className={`order_nav_item ${currOrderNav === 1? 'is_curr_order_nav':''}`} onClick={() => {changeOrderNav(1)}}>待付款</Text>
      <Text className={`order_nav_item ${currOrderNav === 2? 'is_curr_order_nav':''}`} onClick={() => {changeOrderNav(2)}}>待发货</Text>
      <Text  className={`order_nav_item ${currOrderNav === 3? 'is_curr_order_nav':''}`} onClick={() => {changeOrderNav(3)}}>待收货</Text>
    </View>
  )
}
